package com.kcyu.sfherp.mapper.ms;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.kcyu.sfherp.entity.*;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ChzdMapper extends BaseMapper<Chzd> {

    @Select("select * from chzd left join web_zdRead on chzd.dh = web_zdRead.dh and web_zdRead.dh_type = 1 where khname like '%${khname}%' and rq <= '${endTime} 23:59:59' and rq >= '${startTime}' order by rq desc")
    public List<Chzd> queryZDbyCustomNameAndDate(@Param("khname") String khname, @Param("startTime") String startTime, @Param("endTime") String endTime);

    @Select("select * from jhzd left join web_zdRead on jhzd.dh = web_zdRead.dh and web_zdRead.dh_type = 2 where khname like '%${khname}%' and rq <= '${endTime} 23:59:59' and rq >= '${startTime}' order by rq desc")
    public List<Jhzd> queryJHbyCustomNameAndDate(@Param("khname") String khname, @Param("startTime") String startTime, @Param("endTime") String endTime);

    @Select("select * from chmx where dh='${dh}'")
    public List<Chmx> queryZDdetailByDh(@Param("dh") String dh);

    @Select("select * from chzd left join web_zdRead on chzd.dh = web_zdRead.dh and web_zdRead.dh_type = 1 where DateDiff(dd,rq,getdate())=0 order by rq desc")
    public List<Chzd> queryRecentZD();

    @Select("select * from chzd left join web_zdRead on chzd.dh = web_zdRead.dh and web_zdRead.dh_type = 1 where rq >= '${thatDay}' and rq <= '${thatDay} 23:59:59' order by rq desc")
    public List<Chzd> queryThatDay(@Param("thatDay") String thatDay);

    @Select("select * from jhzd left join web_zdRead on jhzd.dh = web_zdRead.dh and web_zdRead.dh_type = 2 where rq >= '${thatDay}' and rq <= '${thatDay} 23:59:59' order by rq desc")
    public List<Jhzd> queryThatDayJH(@Param("thatDay") String thatDay);

    @Select("select * from jhmx where dh='${dh}'")
    public List<CustomHistoryPrice> queryJHdetailByDh(String dh);

    @Select("select * from chzd left join web_zdRead on chzd.dh = web_zdRead.dh where web_zdRead.is_read = 2 and web_zdRead.dh_type = 1 order by chzd.rq DESC")
    public List<Chzd> queryQuestionZD();

    @Select("select * from jhzd left join web_zdRead on jhzd.dh = web_zdRead.dh where web_zdRead.is_read = 2 and web_zdRead.dh_type = 2 order by jhzd.rq DESC")
    public List<Chzd> queryQuestionJHZD();

}

